﻿using System;
using System.Data;
using System.Drawing;
using System.Threading;
using System.Windows.Forms;
using System.Collections.Generic;
using ElectronicWMSA.T_WMS.T_PutOut;
using ElectronicWMSA.Comm.ClassFiles;
using ElectronicWMSA.Comm.Forms.Message;
using WMSABL;

namespace ElectronicWMSA.Warehouse
{
    public partial class List_VersionNOFrm : Form
    {
        private string _IP = "";
        public List_VersionNOFrm()
        {
            InitializeComponent();

            this.pageControl2.PageCurrent = 1;
            this.pageControl2.PageSize = 100;

            this.pageControl3.PageCurrent = 1;
            this.pageControl3.PageSize = 100;
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            timer1.Enabled = false;
            this.pageControl2.Bind();
        }

        #region DBind_VserionData
        private string strWhere = "";
        private int DBindData_Stock_Version()
        {
            Comm.Forms.MsControls.PageData pageData = new Comm.Forms.MsControls.PageData();
            pageData.TableName = "T_Stock";
            pageData.PrimaryKey = "NID";
            pageData.OrderStr = "NID DESC";
            pageData.PageIndex = this.pageControl2.PageCurrent;
            pageData.PageSize = this.pageControl2.PageSize;
            pageData.QueryCondition = strWhere;
            pageData.QueryFieldName = "*";

            WaitingBoxFrm wf = new WaitingBoxFrm((obj, args) => { Thread.Sleep(500); pageData.QueryDataTable(); }, 1200); wf.ShowDialog(this);
            this.pageControl2.bindingSource.DataSource = pageData.dsInfo.Tables[0];
            this.pageControl2.bindingNavigator.BindingSource = pageControl2.bindingSource;
            this.dataGridView2.AutoGenerateColumns = false;
            this.dataGridView2.DataSource = this.pageControl2.bindingSource;
            this.dataGridView2.ClearSelection();
            this.dataGridView2.CurrentCell = null;
            return pageData.TotalCount;
        }
        private string strWhere_PKNO3 = "";
        private int DBindData_PKNO3()
        {
            Comm.Forms.MsControls.PageData pageData = new Comm.Forms.MsControls.PageData();
            pageData.TableName = "T_Stock";
            pageData.PrimaryKey = "NID";
            pageData.OrderStr = "NID DESC";
            pageData.PageIndex = this.pageControl3.PageCurrent;
            pageData.PageSize = this.pageControl3.PageSize;
            pageData.QueryCondition = strWhere_PKNO3;
            pageData.QueryFieldName = "*";

            WaitingBoxFrm wf = new WaitingBoxFrm((obj, args) => { Thread.Sleep(500); pageData.QueryDataTable(); }, 1200); wf.ShowDialog(this);

            this.pageControl3.bindingSource.DataSource = pageData.dsInfo.Tables[0];
            this.pageControl3.bindingNavigator.BindingSource = pageControl3.bindingSource;

            this.dataGridView3.AutoGenerateColumns = false;
            this.dataGridView3.DataSource = this.pageControl3.bindingSource;
            //this.dataGridView3.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
            //this.dataGridView3.MergeColumnNames.Add("PKNO3");
            //this.dataGridView3.MergeColumnNames.Add("PONO3");
            //this.dataGridView3.MergeColumnNames.Add("ProductModel3");
            this.dataGridView3.ClearSelection();
            return pageData.TotalCount;
        }
      
        private int pageControl2_EventPaging(Comm.Forms.MsControls.EventPagingArg e)
        {
            return DBindData_Stock_Version();
        }
        private int pageControl3_EventPaging(Comm.Forms.MsControls.EventPagingArg e)
        {
            return DBindData_PKNO3();
        }
        private void dataGridView2_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
        {
            SolidBrush b = new SolidBrush(dataGridView2.RowHeadersDefaultCellStyle.ForeColor);
            e.Graphics.DrawString((e.RowIndex + 1).ToString(System.Globalization.CultureInfo.CurrentUICulture), dataGridView2.DefaultCellStyle.Font, b, e.RowBounds.Location.X + 20, e.RowBounds.Location.Y + 4);
        }

        private void dataGridView3_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
        {
            SolidBrush b = new SolidBrush(dataGridView3.RowHeadersDefaultCellStyle.ForeColor);
            e.Graphics.DrawString((e.RowIndex + 1).ToString(System.Globalization.CultureInfo.CurrentUICulture), dataGridView3.DefaultCellStyle.Font, b, e.RowBounds.Location.X + 20, e.RowBounds.Location.Y + 4);
        }
        #endregion

        private void linkLabelClose_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            Main._Main.CloseTabPages();
        }
        private void linkLabellinkLabelCloseAll_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            Main._Main.CloseAllTabPages();
        }
        private void linkLabelCloseElse_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            Main._Main.CloseTabPageElse();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSearch2_Click(object sender, EventArgs e)
        {
            strWhere = " BK03!='Option' AND BK03 IS NOT NULL  ";
            if (!string.IsNullOrEmpty(txt_Position.Text.Trim()))
            {
                this.strWhere += "   AND Posiont1 like '%" + txt_Position.Text.Trim() + "%'";
            }
            if (!string.IsNullOrEmpty(txt_machine.Text.Trim()))
            {
                this.strWhere += "   AND   Replace(Product_Model,' ','')  like '%" + txt_machine.Text.Trim() + "'";
            }
            if (!string.IsNullOrEmpty(txt_Seri.Text.Trim()))
            {
                this.strWhere += "   AND Serial_Number like '%" + txt_Seri.Text.Trim() + "%'";
            }
            if (!string.IsNullOrEmpty(cbm_Type.Text.Trim()))
            {
                this.strWhere += "   AND BK03 = '" + cbm_Type.Text.Trim() + "'";
            }
            string _versionEd = cmb_VersionEd.Text.Trim();
            if (_versionEd!=""&& _versionEd != "--请选择--")
            {
                if (_versionEd== "已同步版本")
                {
                this.strWhere += "   AND BK12 IS NOT NULL";
                }
                else if (_versionEd == "未同步版本")
                {
                this.strWhere += "   AND BK12  IS NULL";
                }
            }
            this.pageControl2.Bind();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_ExportVison_Click(object sender, EventArgs e)
        {
            if (dataGridView2.Rows.Count > 0)
            {
                if (MessageClass.enquire("确认导出？") == DialogResult.OK)
                {
                    DataTable dt;
                    string SelectSQL = "SELECT [Product_Model] AS '机型',[Serial_Number] AS '序列号',[BK06] AS '库存数量' ,[Posiont1] AS '库位',[BK03] AS '分类' ,BK12 AS '版本号'  FROM [T_Stock]  ";
                    if (strWhere != "")
                    {
                        SelectSQL += " WHERE " + strWhere + " ";
                    }
                    else
                    {
                        SelectSQL += " WHERE BK03!='Option' AND BK03 IS NOT NULL ";
                    }
                    dt = SYDZ.WMS.DBUtility.DbHelperSQL.ExecuteDataTable(SelectSQL);
                    ExPut.GetNopiExcel(dt);
                }
            }
            else
            {
                MessageClass.warning("请先查询数据！");
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_3_Click(object sender, EventArgs e)
        {
            strWhere_PKNO3 = " BK03!='Option'  AND BK03 IS NOT NULL  AND PickList_NO IS NOT NULL  AND OutList_NO IS NOT NULL  ";

            if (!string.IsNullOrEmpty(txt_PKNO3.Text.Trim()))
            {
                this.strWhere_PKNO3 += "   AND PickList_NO = '" + txt_PKNO3.Text.Trim() + "'";
            }
            if (!string.IsNullOrEmpty(txt_PONum3.Text.Trim()))
            {
                this.strWhere_PKNO3 += "   AND OutList_NO = '" + txt_PONum3.Text.Trim() + "'";
            }
            this.pageControl3.Bind();
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_ExportInfo3_Click(object sender, EventArgs e)
        {
            if (dataGridView3.Rows.Count > 0)
            {
                if (MessageClass.enquire("确认导出？") == DialogResult.OK)
                {
                    DataTable dt;
                    string SelectSQL = "SELECT [PickList_NO] AS 装箱单号,[OutList_NO] AS PO号,[BK10] AS 目的地,[BK08] AS 出厂日期,[Product_Model] AS 机型,[Serial_Number] AS 序列号,[BK12] AS 版本号,[BanHao] AS 板号,BK06 AS 数量, BK13 AS '备注' FROM [DB_WMSFIRST].[dbo].[T_Stock]  ";
                    if (strWhere_PKNO3 != "")
                    {
                        SelectSQL += " WHERE " + strWhere_PKNO3 + " ";
                    }
                    else
                    {
                        SelectSQL += " WHERE BK03!='Option' AND BK03 IS NOT NULL ";
                    }
                    dt = SYDZ.WMS.DBUtility.DbHelperSQL.ExecuteDataTable(SelectSQL);
                    ExPut.GetNopiExcel(dt);
                }
            }
            else
            {
                MessageClass.warning("请先查询数据！");
            }
        }

    }
}
